﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cricket.LinqData;
using Cricket.LinqModel;

public partial class EditAdminBetting : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    Admin admin;
    List<Admin> admins;
    MatchSchedule matchSchedule;
    BettingType bettingType;
    List<BettingType> bettingTypes;
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            bindAdmin();
            bindMatch();
            bindType();
        }
    }

    private void bindType()
    {
        bettingType = new BettingType(_dataObject);
        bettingTypes = new List<BettingType>();
        bettingTypes = bettingType.GetAllBettingType();
        if (bettingTypes.Count > 0)
        {
            drpType.DataSource = bettingTypes;
            drpType.DataTextField = "Type";
            drpType.DataValueField = "Id";
            drpType.DataBind();
            drpType.Items.Insert(0, new ListItem("Select Betting Type", "0"));
        }
    }

    private void bindMatch()
    {
        matchSchedule = new MatchSchedule(_dataObject);
        List<GetMatchesForReportResult> lstResult = new List<GetMatchesForReportResult>();
        lstResult = matchSchedule.GetMatchesForReport();
        if (lstResult.Count > 0)
        {
            drpMatch.DataSource = lstResult;
            drpMatch.DataTextField = "Teams";
            drpMatch.DataValueField = "Id";
            drpMatch.DataBind();
            drpMatch.Items.Insert(0, new ListItem("Select Match", "0"));
        }
    }

    private void bindAdmin()
    {
        admin = new Admin(_dataObject);
        admins = new List<Admin>();
        admins = admin.GetAllAdmin();
        if (admins.Count > 0)
        {
            drpAdmin.DataSource = admins;
            drpAdmin.DataTextField = "FirstName";
            drpAdmin.DataValueField = "Id";
            drpAdmin.DataBind();
            drpAdmin.Items.Insert(0, new ListItem("Select Admin", "0"));
        }
    }

    private void bindAdminBetting()
    {
        Betting betting = new Betting(_dataObject);
        List<EditAdminBetResult> lst = new List<EditAdminBetResult>();
        lst = betting.EditAdminBetting(Convert.ToInt32(drpMatch.SelectedValue), Convert.ToInt32(drpType.SelectedValue), Convert.ToInt32(drpAdmin.SelectedValue));
        if (lst.Count > 0)
        {
            rptAdmin.DataSource = lst;
            rptAdmin.DataBind();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        bindAdminBetting();
    }
    protected void rptAdmin_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        
    }
    protected void rptAdmin_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToString().ToLower().Trim() == "editadmin")
        {
            System.Web.UI.WebControls.RepeaterItem row = (System.Web.UI.WebControls.RepeaterItem)(((System.Web.UI.WebControls.Button)e.CommandSource).NamingContainer);
            System.Web.UI.WebControls.Button btnEdit = (System.Web.UI.WebControls.Button)row.FindControl("btnEdit");
            System.Web.UI.WebControls.TextBox lblOver = (System.Web.UI.WebControls.TextBox)row.FindControl("lblOver");
            System.Web.UI.WebControls.TextBox lblLagadi = (System.Web.UI.WebControls.TextBox)row.FindControl("lblLagadi");
            System.Web.UI.WebControls.TextBox lblKhadhi = (System.Web.UI.WebControls.TextBox)row.FindControl("lblKhadhi");
            System.Web.UI.WebControls.TextBox TeamId = (System.Web.UI.WebControls.TextBox)row.FindControl("TeamId");
            lblOver.Enabled = true;
            lblLagadi.Enabled = true;
            lblKhadhi.Enabled = true;
            TeamId.Enabled = true;
            
        }
    }
}